﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BiliBiliCSharpStudy.old {
    // 声明在名称空间下; 也可以声明在类（class）中，嵌套声明，引用时要带上类名字;
    public delegate double Calc(double x, double y);

    class DelegateDemo2Customize {
        public static void Demo() {
            Test1();
        }

        public static void Test1() {
            Calculator4 calculator = new Calculator4();
            Calc calc1 = new Calc(calculator.Add);
            Calc calc2 = new Calc(calculator.Sub);
            Calc calc3 = new Calc(calculator.Mul);
            Calc calc4 = new Calc(calculator.Div);

            double x = 100;
            double y = 200;
            double z;
            z = calc1.Invoke(x, y);
            Console.WriteLine(z);

            z = calc1(x, y);

            Console.WriteLine(z);
            z = calc2.Invoke(x, y);
            Console.WriteLine(z);
            z = calc3.Invoke(x, y);
            Console.WriteLine(z);
            z = calc4.Invoke(x, y);
            Console.WriteLine(z);
        }

    }

    class Calculator4 {
        public double Add(double x, double y) {
            return x + y;
        }
        public double Sub(double x, double y) {
            return x - y;
        }
        public double Mul(double x, double y) {
            return x * y;
        }
        public double Div(double x, double y) {
            return x / y;
        }
    }
}
